define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'studios/index' + location.search,
                    add_url: 'studios/add',
                    edit_url: 'studios/edit',
                    del_url: 'studios/del',
                    multi_url: 'studios/multi',
                    import_url: 'studios/import',
                    table: 'studios',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'studio_id', title: __('Studio_id')},
                        {field: 'studio_name', title: __('Studio_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'opening_date', title: __('Opening_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'language', title: __('Language'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"active":__('Active'),"inactive":__('Inactive'),"pending":__('Pending')}, formatter: Table.api.formatter.status},
                        {field: 'country', title: __('Country'), operate: 'LIKE'},
                        {field: 'region', title: __('Region'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'longitude', title: __('Longitude'), operate:'BETWEEN'},
                        {field: 'latitude', title: __('Latitude'), operate:'BETWEEN'},
                        {field: 'contact_name', title: __('Contact_name'), operate: 'LIKE'},
                        {field: 'contact_mobile', title: __('Contact_mobile'), operate: 'LIKE'},
                        {field: 'contact_email', title: __('Contact_email'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'language_code', title: __('Language_code')},
                        {field: 'timezone', title: __('Timezone'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'regions.region_name', title: __('Regions.region_name'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
